function main() {		
	var collection;	
	var docEntry;
	var centry;	
	var actLogger;
	var warnings;
	
	var queryParams = sc$APIContext.GetQueryParams();
	var logger = sc$APIContext.GetActionLogger();

	var dic = sc$Context.JsonDeserialize(sc$APIContext.GetImportBuffer());
	
		

	collection = sc$Context.DataObjects.GetMasterByID("Hercules", "SalesEntries",dic["FirstBOID"].toString());
	collection.Logic.DisableConstraints();
	docEntry = collection[0];
	centry = docEntry.ComEntries[0];
	
	
	if(dic["FirstBOID"] != null){				
		var sqltext = "select heCommercialEntries.HEID,HEREGION from heCommercialEntries where heCommercialEntries.HEDENTID='"+dic["FirstBOID"].toString()+"'";
		var argsText= new scDbCommandArgs();				
		var	CommValues = sc$Db.ExecuteResultSet(sqltext,argsText)								
	}
	
	centry.SetValue("REGION", CommValues.Tables[0].Rows[0]["HEREGION"].toString()+'.');			
	centry.EndEdit();	
	docEntry.EndEdit();
	
	sc$Context.DataObjects.ExternalDataFix("Hercules", "SalesEntries", collection);
	actLogger = sc$ApplImportScript.SaveFromImport("Hercules", "SalesEntries", collection);
	logger.Merge(actLogger);
	
	
	
	var collection2 = sc$Context.DataObjects.GetMasterByID("Hercules", "SalesEntries",dic["FirstBOID"].toString());		
	var docEntry2 = collection2[0];
	
	var centry2 = docEntry2.ComEntries[0];
	centry2.SetValue("REGION", CommValues.Tables[0].Rows[0]["HEREGION"].toString());
	centry2.EndEdit();
	docEntry2.EndEdit();
	sc$Context.DataObjects.ExternalDataFix("Hercules", "SalesEntries", collection2);
	actLogger = sc$ApplImportScript.SaveFromImport("Hercules", "SalesEntries", collection2);
		
	
	var outDic = new scDictionary();
	outDic["Cookie"]  = sc$APIContext.GetCookie();
	outDic["EntityId"] = docEntry.ID;
	outDic["Messages"] = logger;

	return sc$Context.JsonSerialize(outDic);
}

function FindLookupItem(codeVal, nameVal, lookupTable, propName, entity, lookupVersion) {	
	var recID = sc$ApplImportScript.FindArrayCodeNameRecord(lookupTable, codeVal, nameVal, lookupVersion);	
	if (recID != null) {		
		entity.SetValue(propName, recID); 
	}
}